package com.huawei.appgallery.forum.posts.card;

import android.content.Context;
import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.ViewStub.OnInflateListener;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import com.huawei.appgallery.common.media.api.IImagePreviewProtocol;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.bean.Post;
import com.huawei.appgallery.forum.base.card.bean.VideoInfo;
import com.huawei.appgallery.forum.base.image.ForumPostImageView;
import com.huawei.appgallery.forum.cards.widget.ForumRoundCornerLayout;
import com.huawei.appgallery.forum.cards.widget.PostTitleTextView;
import com.huawei.appgallery.forum.cards.widget.UserInfoTextView;
import com.huawei.appgallery.forum.option.post.view.PostCardLinkView;
import com.huawei.appgallery.forum.user.api.IUserFollow;
import com.huawei.appgallery.forum.user.api.IUserHomePageProtocol;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appmarket.support.video.VideoPlayer;
import huawei.widget.HwButton;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.blc;
import o.bqy;
import o.brd;
import o.brk;
import o.brl;
import o.brs;
import o.bsx;
import o.bsy;
import o.bsy.a;
import o.bsy.c;
import o.btc;
import o.btu;
import o.byf;
import o.byl;
import o.bzd;
import o.bzd.b;
import o.bzd.d;
import o.bzd.h;
import o.bzd.j;
import o.bzr;
import o.cgz;
import o.dmn;
import o.dmp;
import o.dmq;
import o.dmr;
import o.dof;
import o.dok;
import o.eqx;
import o.evp;
import o.evx;
import o.fho;
import o.fiu;
import o.fjb;
import o.fjo;
import o.fjq;

public class ForumPostDetailHeadCard extends ForumCard implements com.huawei.appgallery.forum.cards.widget.UserInfoTextView.e {
    protected View ʻ;
    private Handler ʻॱ = new Handler();
    protected TextView ʼ;
    protected ViewGroup ʽ;
    protected ImageView ˊ;
    protected TextView ˊॱ;
    protected TextView ˋ;
    protected int ˋॱ = 0;
    protected UserInfoTextView ˎ;
    protected PostTitleTextView ˏ;
    ArrayList<blc> ˏॱ = new ArrayList();
    protected HwButton ͺ;
    protected ForumPostDetailHeadCardBean ॱ;
    protected ViewStub ॱˊ;
    protected VideoPlayer ॱˋ;
    protected boolean ॱˎ = false;
    protected TextView ॱॱ;
    protected View ॱᐝ;
    protected TextView ᐝ;
    private String ᐝॱ = null;

    class e implements OnClickListener {
        private int ˊ;
        final /* synthetic */ ForumPostDetailHeadCard ˋ;

        public e(ForumPostDetailHeadCard forumPostDetailHeadCard, int i) {
            this.ˋ = forumPostDetailHeadCard;
            this.ˊ = i;
        }

        public void onClick(View view) {
            this.ˋ.ˎ(this.ˊ);
        }
    }

    public ForumPostDetailHeadCard(Context context) {
        super(context);
    }

    protected void ˎ(int i) {
        fjb ˎ = fho.ˏ().ˋ("Media").ˎ("ImagePreview");
        IImagePreviewProtocol iImagePreviewProtocol = (IImagePreviewProtocol) ˎ.ˊ();
        iImagePreviewProtocol.setSavePath(Environment.getExternalStorageDirectory() + "/Pictures/" + this.ʼॱ.getString(j.ʻ));
        iImagePreviewProtocol.setOffset(i);
        iImagePreviewProtocol.setImageBeans(this.ˏॱ);
        fiu.ˊ().ˏ(ˉ().getContext(), ˎ);
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ˏ = (PostTitleTextView) view.findViewById(b.ͺˏ);
        azb.ˏ(this.ˏ);
        azb.ˏ(view, b.ߴ);
        this.ˊ = (ImageView) view.findViewById(b.ˎͺ);
        this.ˋ = (TextView) view.findViewById(b.ˏͺ);
        this.ᐝ = (TextView) view.findViewById(b.ˑॱ);
        this.ʻ = view.findViewById(b.ꓸ);
        azb.ˏ(this.ʻ);
        this.ʼ = (TextView) view.findViewById(b.ꜟ);
        this.ˎ = (UserInfoTextView) view.findViewById(b.ͺˎ);
        this.ʽ = (ViewGroup) view.findViewById(b.ʿॱ);
        azb.ˏ(this.ʽ);
        this.ॱॱ = (TextView) view.findViewById(b.ˋʻ);
        azb.ˏ(this.ॱॱ);
        this.ˊॱ = (TextView) view.findViewById(b.ٴ);
        this.ˎ.setFakeView(this.ˊॱ);
        this.ˎ.setUserFakeViewChangeListener(this);
        this.ॱˊ = (ViewStub) view.findViewById(b.ॱﹳ);
        if (this.ॱˊ != null) {
            this.ॱˊ.setOnInflateListener(new OnInflateListener(this) {
                final /* synthetic */ ForumPostDetailHeadCard ॱ;

                {
                    this.ॱ = r1;
                }

                public void onInflate(ViewStub viewStub, View view) {
                    this.ॱ.ॱˎ = true;
                }
            });
        }
        this.ˎ.setShowHostStamp(false);
        this.ˎ.setShowModeratorStamp(true);
        this.ͺ = (HwButton) view.findViewById(b.ˊʼ);
        this.ͺ.setOnClickListener(new evx(this) {
            final /* synthetic */ ForumPostDetailHeadCard ˎ;

            {
                this.ˎ = r1;
            }

            public void ˋ(View view) {
                this.ˎ.ॱॱ();
            }
        });
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof ForumPostDetailHeadCardBean) {
            this.ॱ = (ForumPostDetailHeadCardBean) cardBean;
            if (!(this.ॱ.ᐝ() == null || this.ॱ.ʼ() == null || this.ॱ.ʽ() == null)) {
                this.ˏ.setTextViewWidth(azb.ॱ(this.ʼॱ));
                this.ˏ.setData(this.ॱ.ᐝ().ˊ(), this.ॱ.ᐝ().ˋ());
                ʼ();
                this.ˋ.setText(this.ॱ.ʽ().ˏ());
                this.ᐝ.setText(btc.ˏ(ˉ().getContext(), this.ॱ.ᐝ().ˎ()));
                if (this.ॱ.ᐝ().ॱˊ() == 3) {
                    this.ʻ.setVisibility(0);
                    this.ʼ.setText(j.ॱॱ);
                } else if (this.ॱ.ᐝ().ॱˊ() == 2) {
                    this.ʻ.setVisibility(0);
                    this.ʼ.setText(j.ॱˋ);
                } else {
                    this.ʻ.setVisibility(8);
                }
                ˏ(this.ॱ.ᐝ());
                ˊ(this.ॱ.ˋॱ());
                this.ˊॱ.setOnClickListener(new OnClickListener(this) {
                    final /* synthetic */ ForumPostDetailHeadCard ˏ;

                    {
                        this.ˏ = r1;
                    }

                    public void onClick(View view) {
                        this.ˏ.ˊ(this.ˏ.ॱ);
                    }
                });
                this.ˋॱ = this.ॱ.ʼ().ʻॱ();
                ˋ(this.ˋॱ);
                if (this.ॱ.ʼ().ʼ() || this.ॱ.ʼ().ॱ() == null) {
                    ˎ(this.ͺ, 8);
                } else {
                    ˎ(this.ͺ, 0);
                }
                ʽ();
            }
        }
        ˎ(this.ॱ);
    }

    private void ʼ() {
        if (TextUtils.isEmpty(this.ॱ.ʼ().ˎ())) {
            this.ˊ.setImageResource(a.ॱˋ);
        } else {
            bsx.ˏ(this.ʼॱ, this.ˊ, this.ॱ.ʼ().ˎ());
        }
        this.ˊ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ForumPostDetailHeadCard ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(View view) {
                this.ˏ.ˊ(this.ˏ.ॱ);
            }
        });
    }

    protected void ˎ(ForumPostDetailHeadCardBean forumPostDetailHeadCardBean) {
        VideoInfo ʽ = forumPostDetailHeadCardBean.ᐝ().ʽ();
        if (forumPostDetailHeadCardBean.ᐝ().ᐝॱ() && ˋ(ʽ)) {
            if (!this.ॱˎ) {
                View inflate = this.ॱˊ.inflate();
                this.ॱˋ = (VideoPlayer) inflate.findViewById(b.ॱꜞ);
                this.ॱᐝ = inflate.findViewById(b.ᐧॱ);
            }
            ॱ(forumPostDetailHeadCardBean);
        }
    }

    protected void ॱ(ForumPostDetailHeadCardBean forumPostDetailHeadCardBean) {
        int i = ˉ().getResources().getConfiguration().orientation;
        if (i == 2) {
            if (this.ॱˋ != null) {
                this.ॱˋ.setVisibility(0);
                ˏ(forumPostDetailHeadCardBean);
            }
        } else if (i == 1 && this.ॱˋ != null) {
            this.ॱˋ.setVisibility(8);
        }
    }

    private void ˏ(ForumPostDetailHeadCardBean forumPostDetailHeadCardBean) {
        if (this.ॱᐝ != null && this.ॱˋ != null) {
            VideoInfo ʽ = forumPostDetailHeadCardBean.ᐝ().ʽ();
            int i = c.ʻ;
            int i2 = c.ˊॱ;
            String str = (String) this.ॱᐝ.getTag(i);
            String str2 = (String) this.ॱᐝ.getTag(i2);
            String ˎ = ʽ.ˎ();
            String ˊ = ʽ.ˊ();
            if (!TextUtils.isEmpty(str) && str.equals(ˎ)) {
                return;
            }
            if (TextUtils.isEmpty(str2) || !str2.equals(ˊ)) {
                this.ॱᐝ.setTag(i, ˎ);
                this.ॱᐝ.setTag(i2, ˊ);
                LayoutParams layoutParams = (LayoutParams) this.ॱˋ.getLayoutParams();
                layoutParams.height = (ʻ() * 9) / 16;
                this.ॱˋ.setLayoutParams(layoutParams);
                this.ॱˋ.setVideoBaseInfo(new evp.b().ˎ(ʽ.ॱ()).ˊ(ˊ).ˋ(ˎ).ʼ(ʽ.ˋ()).ᐝ(ʽ.ˋ()).ʻ(ʽ.ˏ()).ॱॱ(ʽ.ʻ()).ॱ());
                eqx.ˎ(this.ॱˋ.ॱॱ(), ˊ);
                this.ॱˋ.ॱॱ().setContentDescription(forumPostDetailHeadCardBean.v_());
            }
        }
    }

    protected boolean ˋ(VideoInfo videoInfo) {
        if (videoInfo == null || dof.ॱ(videoInfo.ˎ())) {
            return false;
        }
        return true;
    }

    private void ʽ() {
        this.ͺ.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) {
            final /* synthetic */ ForumPostDetailHeadCard ˊ;

            {
                this.ˊ = r1;
            }

            public boolean onPreDraw() {
                this.ˊ.ͺ.getViewTreeObserver().removeOnPreDrawListener(this);
                this.ˊ.ˎ.setContentWidth((this.ˊ.ʻ() - this.ˊ.ͺ.getMeasuredWidth()) - (this.ˊ.ʼॱ.getResources().getDimensionPixelOffset(d.ˏ) * 2));
                this.ˊ.ˎ.setData(this.ˊ.ॱ.ʼ());
                return true;
            }
        });
    }

    protected int ʻ() {
        return (azb.ॱ(this.ʼॱ) - (this.ʼॱ.getResources().getDimensionPixelOffset(o.bsy.e.ʿ) * 3)) - this.ʼॱ.getResources().getDimensionPixelOffset(o.bsy.e.ˎˎ);
    }

    protected void ˊ(ForumPostDetailHeadCardBean forumPostDetailHeadCardBean) {
        fjb ˎ = fho.ˏ().ˋ("User").ˎ("UserHomePageActivity");
        IUserHomePageProtocol iUserHomePageProtocol = (IUserHomePageProtocol) ˎ.ˊ();
        iUserHomePageProtocol.setUri("forum|user_detail");
        iUserHomePageProtocol.setUserId(forumPostDetailHeadCardBean.ʼ().ॱ());
        iUserHomePageProtocol.setType(forumPostDetailHeadCardBean.ʼ().ˊ());
        iUserHomePageProtocol.setDomainId(forumPostDetailHeadCardBean.ॱ());
        fiu.ˊ().ˏ(ˉ().getContext(), ˎ);
    }

    private void ˊ(String str) {
        if (TextUtils.isEmpty(str)) {
            this.ॱॱ.setVisibility(8);
        } else {
            this.ॱॱ.setText(str);
        }
    }

    private void ˏ(Post post) {
        if (this.ʽ.getChildCount() <= 0 || !(TextUtils.isEmpty(this.ᐝॱ) || this.ᐝॱ.equals(post.ॱ()))) {
            this.ᐝॱ = post.ॱ();
            List<byf> ˊ = bzr.ˊ(post);
            this.ˏॱ.clear();
            this.ʽ.removeAllViews();
            int ˎ = ˎ();
            int size = ˊ.size();
            int i = 0;
            int i2 = 0;
            for (byf o_byf : ˊ) {
                if (o_byf.ॱ() == 1) {
                    this.ʽ.addView(ˊ(o_byf));
                } else if (o_byf.ॱ() == 0) {
                    View ˋ = ˋ(o_byf, i2, ˎ);
                    if (ˋ == null) {
                        this.ʽ.addView(ˊ(o_byf, i2, ˎ));
                    } else {
                        this.ʽ.addView(ˋ);
                    }
                    i2++;
                    this.ˏॱ.add(ॱ(o_byf));
                } else if (o_byf.ॱ() == 2) {
                    this.ʽ.addView(ˎ(o_byf));
                    ᐝ();
                }
                i++;
                if (i < size) {
                    this.ʽ.addView(ˏ(o_byf));
                }
            }
        }
    }

    private void ᐝ() {
        if (this.ʽ.getChildCount() >= 2) {
            this.ʽ.getChildAt(this.ʽ.getChildCount() - 2).setLayoutParams(new LinearLayout.LayoutParams(-1, (int) this.ʼॱ.getResources().getDimension(d.ʼ)));
        }
    }

    private View ˏ(byf o_byf) {
        View view = new View(ˉ().getContext());
        int dimension = (int) this.ʼॱ.getResources().getDimension(d.ॱॱ);
        if (o_byf.ॱ() == 2) {
            dimension = (int) this.ʼॱ.getResources().getDimension(d.ʼ);
        }
        view.setLayoutParams(new LinearLayout.LayoutParams(-1, dimension));
        return view;
    }

    private blc ॱ(byf o_byf) {
        blc o_blc = new blc();
        o_blc.ॱ(o_byf.ˎ().ˋॱ());
        o_blc.ॱ(o_byf.ˎ().ͺ());
        o_blc.ˋ(o_byf.ˎ().ॱˊ());
        o_blc.ˋ(o_byf.ˎ().ʽ());
        return o_blc;
    }

    private PostCardLinkView ˎ(byf o_byf) {
        PostCardLinkView postCardLinkView = new PostCardLinkView(this.ʼॱ);
        postCardLinkView.setCardLinkDate(o_byf.ˊ());
        postCardLinkView.setTrace(this.ॱ.u_());
        return postCardLinkView;
    }

    private ImageView ˋ(byf o_byf, int i, int i2) {
        if (ˋ(o_byf) && !dok.ᐝ(this.ʼॱ)) {
            return null;
        }
        ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
        ˋ(o_byf, i2, this.ʼॱ, layoutParams);
        ImageView imageView = (ImageView) LayoutInflater.from(this.ʼॱ).inflate(bsy.b.ॱˊ, null);
        imageView.setLayoutParams(layoutParams);
        imageView.setOnClickListener(new e(this, i));
        bzr.ˋ(imageView, o_byf.ˎ().ʽ(), bsx.ˋ());
        return imageView;
    }

    private ForumRoundCornerLayout ˊ(byf o_byf, int i, int i2) {
        ForumRoundCornerLayout forumRoundCornerLayout = (ForumRoundCornerLayout) LayoutInflater.from(this.ʼॱ).inflate(bsy.b.ͺ, null);
        final ForumPostImageView forumPostImageView = (ForumPostImageView) forumRoundCornerLayout.findViewById(b.ˎˏ);
        ViewGroup.LayoutParams layoutParams = new LayoutParams(-1, -2);
        ˋ(o_byf, i2, this.ʼॱ, layoutParams);
        forumPostImageView.setLayoutParams(layoutParams);
        ViewGroup.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-2, -2);
        layoutParams2.height = layoutParams.height;
        layoutParams2.width = layoutParams.width;
        forumRoundCornerLayout.setLayoutParams(layoutParams2);
        forumPostImageView.setOnClickListener(new e(this, i));
        String ʽ = o_byf.ˎ().ʽ();
        forumPostImageView.setImageUrl(ʽ);
        dmq.ˏ.ˋ(new dmr(dmp.CONCURRENT, dmn.NORMAL, new brl(this.ʼॱ, forumPostImageView, ʽ, new brk(this) {
            final /* synthetic */ ForumPostDetailHeadCard ॱ;

            public void ˎ(boolean z, final File file) {
                if (z && file != null) {
                    this.ॱ.ʻॱ.post(new Runnable(this) {
                        final /* synthetic */ AnonymousClass6 ˋ;

                        public void run() {
                            forumPostImageView.setImage(new brs(file));
                        }
                    });
                }
            }
        })));
        return forumRoundCornerLayout;
    }

    private boolean ˋ(byf o_byf) {
        byl ˎ = o_byf.ˎ();
        if (ˎ == null || bsx.ˎ(ˎ.ʽ()) || ˎ.ॱˊ() <= bsx.ˋ()) {
            return false;
        }
        return true;
    }

    public int ˎ() {
        WindowManager windowManager = (WindowManager) ˉ().getContext().getSystemService("window");
        DisplayMetrics displayMetrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(displayMetrics);
        return (displayMetrics.widthPixels - azb.ˊ(this.ʼॱ)) - azb.ˏ(this.ʼॱ);
    }

    private void ˋ(byf o_byf, int i, Context context, ViewGroup.LayoutParams layoutParams) {
        String ʽ = o_byf.ˎ().ʽ();
        int ͺ = o_byf.ˎ().ͺ();
        int ॱˊ = o_byf.ˎ().ॱˊ();
        boolean ˎ = bsx.ˎ(ʽ);
        if (ͺ <= 0 || ॱˊ <= 0) {
            layoutParams.width = i;
            layoutParams.height = (int) (0.5f * ((float) i));
            return;
        }
        float f = ((float) ॱˊ) / ((float) ͺ);
        if (ˎ) {
            layoutParams.width = i;
            layoutParams.height = (int) (((float) i) * f);
        } else if (ͺ < i) {
            layoutParams.width = ͺ;
            layoutParams.height = ॱˊ;
        } else {
            layoutParams.width = i;
            layoutParams.height = (int) (((float) i) * f);
        }
    }

    private View ˊ(byf o_byf) {
        View inflate = LayoutInflater.from(this.ʼॱ).inflate(h.ˊॱ, null);
        TextView textView = (TextView) inflate.findViewById(b.ˈॱ);
        textView.setText(btu.ॱ(this.ʼॱ, o_byf.ˏ(), btu.ॱ()));
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        ˎ(textView);
        if (TextUtils.isEmpty(o_byf.ˏ())) {
            textView.setVisibility(8);
        }
        return inflate;
    }

    protected void ˎ(TextView textView) {
    }

    public void ˊ(int i) {
        this.ˊॱ.setWidth((this.ʼॱ.getResources().getDimensionPixelSize(d.ˏॱ) + (this.ʼॱ.getResources().getDimensionPixelSize(d.ʽ) * 2)) + i);
    }

    protected void ॱॱ() {
        int i = 1;
        if (!(1 == this.ˋॱ || 2 == this.ˋॱ)) {
            i = 0;
        }
        ॱ(i).ˏ(new fjq<IUserFollow.b>(this) {
            final /* synthetic */ ForumPostDetailHeadCard ˏ;

            public void onComplete(fjo<IUserFollow.b> o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b) {
                if (o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ˊ() && ((IUserFollow.b) o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ॱ()).ˏ() == 0) {
                    this.ˏ.ˋॱ = ((IUserFollow.b) o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ॱ()).ˋ();
                    this.ˏ.ॱ.ʼ().ˎ(this.ˏ.ˋॱ);
                    this.ˏ.ˋ(this.ˏ.ˋॱ);
                    this.ˏ.ʽ();
                    brd.ॱ.ˋ(bqy.ˋ().ˎ(this.ˏ.ʼॱ), bqy.ˋ().ˎ(), this.ˏ.ॱ.ॱˈ(), "POST", i == 0 ? 1 : 0);
                }
            }
        });
    }

    protected fjo<IUserFollow.b> ॱ(int i) {
        return ((IUserFollow) fho.ˏ().ˋ("User").ॱ(IUserFollow.class)).ॱ(this.ʼॱ, this.ॱ.ʼ(), i);
    }

    protected void ˋ(int i) {
        if (i == 1) {
            this.ˋॱ = i;
            this.ͺ.setText(j.ʼ);
            this.ͺ.setTextColor(this.ʼॱ.getResources().getColor(bzd.a.ˊ));
        } else if (i == 2) {
            this.ˋॱ = i;
            this.ͺ.setText(j.ʽ);
            this.ͺ.setTextColor(this.ʼॱ.getResources().getColor(bzd.a.ˊ));
        } else {
            this.ˋॱ = i;
            this.ͺ.setText(j.ᐝ);
            this.ͺ.setTextColor(this.ʼॱ.getResources().getColor(bzd.a.ˋ));
        }
    }

    private void ˎ(View view, int i) {
        if (i != view.getVisibility()) {
            view.setVisibility(i);
        }
    }
}
